import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeMap;

/**
 * Created by zhangjinrui on 17/6/27.
 */

class Interval {
    int start;
    int end;

    Interval() {
        start = 0;
        end = 0;
    }

    Interval(int s, int e) {
        start = s;
        end = e;
    }
}

public class Solution436 {

    public static void main(String args[]) {
        Solution436 s = new Solution436();
    }

    public int[] findRightInterval(Interval[] intervals) {
        TreeMap<Integer, Integer> mp = new TreeMap<>();
        int[] ret = new int[intervals.length];
        for(int i = 0 ; i < intervals.length ; i ++){
            mp.put(intervals[i].start, i);
        }

        for(int i = 0 ; i < intervals.length ; i ++){
            ret[i] = (mp.ceilingEntry(intervals[i].end) == null? -1 :  mp.ceilingEntry(intervals[i].end).getValue());
        }
        return ret;
    }

}
